<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	class Contact extends MX_Controller
	{
		private $module = "contact";
		
		public function __construct()
		{
			parent::__construct();
			$this->load->model($this->module.'_model','model');
			$this->load->library('pagination');
			
			$this->template->set_template('admin');
			$this->template->write('title','Shopping Cart - Contact');
			$this->template->write_view('menu','BACKEND/menu');
			$this->template->write_view('search','BACKEND/search');
			$this->template->write_view('left','BACKEND/menu_left');
			$this->template->write_view('footer','BACKEND/footer');
		}
		
		public function admin_index()
		{		
			$result = $this->model->admin_index();
				
			$data = array(
				'module'	 => $this->module,
				'result'	 => $result
			);
			
			$this->template->write_view('content','BACKEND/index',$data);
			$this->template->render();
		}
		
		public function admin_save()
		{
			if($_POST)
			{				
				if($this->model->admin_save())
				{
					header('Location: '.base_url().'index.php/admin/'.$this->module.'/');
				}
			}
			header('Location: '.base_url().'index.php/admin/'.$this->module.'/');
		}
			
		public function admin_update($id = 0)
		{
			$result[0] = array();
			if($id != 0)
			{
				$result = $this->model->admin_update($id);
			}
			$data = array(
					'result'   	 	=> $result[0],
					'module'   	 	=> $this->module
			);
			
			$this->template->write_view('content','BACKEND/update',$data);
			$this->template->render();
		}
		
		public function admin_del($id = 0)
		{
			$id = intval($id);
			$this->model->admin_del($id);
			header('location: '.base_url().'index.php/admin/'.$this->module.'/');
		}
		
		public function admin_update_status()
		{
			$id = $this->input->post('id');
			if($this->input->post('status') == 1)
			{
				$status = 0;
			}else{
				$status = 1;
			}
			
			$this->model->admin_update_status($id,$status);
			
			$data_update = array(
				'id'=>$id,
				'status'=>$status
			);
			
			$this->load->view('BACKEND/ajax_status',$data_update);
		}
		
		// Update Bestsale
		
		
		public function admin_del_all()
		{
			if($_POST)
			{
				$this->model->admin_del_all();
				header('Location: '.base_url().'index.php/admin/'.$this->module.'/');
			}else{
				header('Location: '.base_url().'index.php/admin/'.$this->module.'/');
			}
		}
		
		public function admin_search()
		{
			$data = array();
			if($_POST)
			{
				$result = $this->model->admin_search();
				$data = array(
					'module' => $this->module,
					'result' => $result
				);
				
				$this->template->write_view('content','BACKEND/index',$data);
				$this->template->render();
			}else{
				header('Location: '.base_url().'index.php/admin/'.$this->module.'/');
			}
		}
		
		
		public function save_massage()
		{
			if($_POST)
			{	
				$this->model->save_massage();
			}
			
		}
	}
?>